<template>
  <view>
    <button @click="getSwiperList">点击</button>
    <!-- 搜索框 -->
    <Ygosearch></Ygosearch>

    <!-- 轮播图 -->
    <u-swiper :list="swiperList" name="image_src" height="340"></u-swiper>

    <!-- 导航 -->
    <view class="nav u-flex">
      <navigator
        v-for="item in navList"
        :key="item.name"
        class="u-flex-1 u-p-15"
      >
        <u-image width="100%" mode="widthFix" :src="item.image_src"></u-image>
      </navigator>
    </view>

    <!-- 楼层 -->
    <view class="floor">
      <view
        class="floor-item"
        v-for="item1 in floorList"
        :key="item1.floor_title.name"
      >
        <view class="floor-title">
          <u-image
            :src="item1.floor_title.image_src"
            width="100%"
            mode="widthFix"
          ></u-image>
        </view>
        <view class="item-content">
          <navigator v-for="item2 in item1.product_list" :key="item2.name">
            <u-image
              :src="item2.image_src"
              width="100%"
              height="100%"
              mode="scaleToFill"
            ></u-image>
          </navigator>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      // 轮播图列表
      swiperList: [],
      // 导航列表
      navList: [],
      // 楼层数据
      floorList: [],
    };
  },
  onLoad() {
    this.getSwiperList();
    this.getNavList();
    this.getFloorList();
  },
  methods: {
    // 获取轮播图数据
    async getSwiperList() {
      this.swiperList = await this.$u.get("/home/swiperdata");
    },
    // 获取导航数据
    async getNavList() {
      this.navList = await this.$u.get("/home/catitems");
    },
    // 获取楼层数据
    async getFloorList() {
      this.floorList = await this.$u.get("/home/floordata");
    },
  },
};
</script>

<style lang="scss" scoped>
.floor-item {
  padding: 12rpx;
}
.item-content {
  overflow: hidden;
  navigator {
    float: left;
    // 设置第一张图大小
    &:nth-child(1) {
      width: 232rpx;
      height: 386rpx;
    }
    // 设置最后4张图大小
    &:nth-last-child(-n + 4) {
      width: 233rpx;
      height: 188rpx;
    }
    // 给2 4 张图设置边距
    &:nth-child(2),
    &:nth-child(4) {
      margin: 0 15rpx;
    }
    // 给最后两张图设置边距
    &:nth-last-child(-n + 2) {
      margin-top: 10rpx;
    }
  }
}
</style>
